package com.huli.controller;
import com.huli.domain.OrderInfo;
import com.huli.service.HuliAddressService;
import com.huli.service.OrderInfoService;
import com.huli.service.PatientService;
import com.huli.util.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/order")
@RestController
public class OrderComtroller {
    @Autowired
    private OrderInfoService orderInfoService;
    @Autowired
    private HuliAddressService huliAddressService;
    @Autowired
    private PatientService patientService;
  //将订单添加方法
    @RequestMapping("insertByAddressId")
  public void insertOrder(@RequestBody OrderInfo orderInfo){
       orderInfoService.insertOrder(orderInfo);
  }
  //回显订单中上门地址
    @RequestMapping("selectByAddressId")
    public String selectByAddressId(Integer id){

      return huliAddressService.findAdderss(id);
  }
  //回显患者信息
    @RequestMapping("selectByPatientId")
    public String selectByPatientId(Integer id){
        return patientService.findPatient(id);
    }
    //取消订单
    @RequestMapping("deleteById")
    public Integer deleteById(Integer id){
        return orderInfoService.deleteById(id);
    }
    //查询订单列表
    @RequestMapping("findAll")
    public Result findAll(Integer userId){
        List<OrderInfo> all = orderInfoService.findAll(userId);
        return Result.success(all);
    }
    //根据id查询订单信息
    @RequestMapping("findByIdToList")
    public OrderInfo findById(Integer id){
        return orderInfoService.findById(id);
    }
    //根据订单状态查询
    @RequestMapping("findByStatus")
    public List<OrderInfo> findByOrderStatus(@Param("orderStatus") Integer orderStatus, @Param("userId") Integer userId){

        return orderInfoService.findByOrderStatus(orderStatus, userId);
    }
    //删除订单
    @RequestMapping("deleteByOrder")
    public Integer deleteByOrder(Integer id){
        return orderInfoService.deleteByOrder(id);
    }
    //修改单条消息状态
    @RequestMapping("updateMessageStatus")
    public String updateMessageStatus(Integer id,String messageStatus){
        return orderInfoService.updateMessageStatus(id, messageStatus);
    }
    //修改全部消息状态
    @RequestMapping("updateMessageStatusAll")
    public List<OrderInfo> updateMessageStatusAll(OrderInfo orderInfo,String messageStatus){
        return orderInfoService.updateMessageStatusll(orderInfo, messageStatus);
    }
}
